//package com.zl.zsk.service.rabbitmq;
//
//import com.rabbitmq.client.Channel;
//import com.zl.zsk.config.RabbitMqConfig;
//import lombok.extern.slf4j.Slf4j;
//import org.springframework.amqp.core.ExchangeTypes;
//import org.springframework.amqp.core.Message;
//import org.springframework.amqp.rabbit.annotation.*;
//import org.springframework.stereotype.Component;
//
//import java.io.IOException;
//
//
///**
// * @author lxb
// * @version 1.0.0
// * @desc: 业务消费者
// * @date 2020-03-18 16:20
// */
//@Component
//@Slf4j
//public class BusinessConsumer {
//
//    /**
//     * 监听A队列
//     * @param message
//     * @param channel
//     * @throws IOException
//     */
//    @RabbitListener(queues = RabbitMqConfig.LXB_A_BUSINESS_QUEUE)
//    public void receiveABusinessMessage(Message message, Channel channel) throws IOException {
//        String msg = new String(message.getBody());
//        log.info("收到业务a的消息:{}",msg);
//        boolean ack = true;
//        Exception exception = null;
//        try {
//            if (msg.contains("deadletter")){
//                throw new RuntimeException("dead letter exception");
//            }
//        } catch (Exception e){
//            ack = false;
//            exception = e;
//        }
//        if (!ack){
//            log.error("消息消费发生异常，error msg:{}", exception.getMessage(), exception);
//            channel.basicNack(message.getMessageProperties().getDeliveryTag(), false, false);
//        } else {
//            channel.basicAck(message.getMessageProperties().getDeliveryTag(), false);
//        }
//    }
//
//    @RabbitListener(queues = RabbitMqConfig.LXB_B_BUSINESS_QUEUE)
//    public void receiveBBusinessMessage(Message message, Channel channel) throws IOException{
//        log.info("收到业务消息B：{}",new String(message.getBody()));
//        channel.basicAck(message.getMessageProperties().getDeliveryTag(), false);
//    }
//
//    @RabbitListener(queues = RabbitMqConfig.LXB_DEAD_LETTER_A_QUEUE)
//    public void receiveA(Message message, Channel channel) throws IOException {
//        System.out.println("收到死信消息A：" + new String(message.getBody()));
//        channel.basicAck(message.getMessageProperties().getDeliveryTag(), false);
//    }
//
//    @RabbitListener(queues = RabbitMqConfig.LXB_DEAD_LETTER_B_QUEUE)
//    public void receiveB(Message message, Channel channel) throws IOException {
//        System.out.println("收到死信消息A：" + new String(message.getBody()));
//        channel.basicAck(message.getMessageProperties().getDeliveryTag(), false);
//    }
//
//
//    @RabbitListener(bindings = @QueueBinding(
//            value = @Queue(value = "${mq.second.kill.dead.real.queue}"),
//            exchange = @Exchange(value = "${mq.second.kill.dead.exchange}",type = ExchangeTypes.DIRECT),
//            key ="${mq.second.kill.dead.real.routing.key}"
//            )
//    )
//    public void handleOrderTimeOutBeforePay(Message message, Channel channel){
//        //log.info("收到了死信队列的消息>>>>消息id为：{},发送消息时间:{}",rabbitMQMessage.getMessageId(),rabbitMQMessage.getTime());
//        try {
//            log.info("通过乐观锁的方式修改数据库记录：当数据状态为未付款状态时，则修改该订单状态为取消");
//            Thread.sleep(1000L);
//            channel.basicAck(message.getMessageProperties().getDeliveryTag(),false);
//        } catch (Exception e) {
//            log.error("捕获到异常");
//            e.printStackTrace();
//        }
//    }
//
//}
